//
//  ShareCenterServiceHandler.m
//  ShareCenter
//
//  Created by yutao on 14-2-23.
//  Copyright (c) 2014年 yutao. All rights reserved.
//

#import "ShareCenterServiceHandler.h"
#import "ShareClientUserInfo.h"

@implementation ShareCenterServiceHandler

+ (SNShareClientType)serviceTypeForNotification:(NSNotification *)note
{
    return [[[note userInfo] objectForKey:SNShareServiceTypeKey] intValue];
}

+ (NSDictionary *)userInfoForNotification:(NSNotification *)note
{
    return [[note userInfo] objectForKey:SNShareServiceUserInfoKey];
}

+ (ShareClientUserInfo *)shareServiceUserInfoForNotification:(NSNotification *)note
{
    return [[note userInfo] objectForKey:SNShareServiceUserInfoKey];
}

+ (ShareClientOAuthInfo *)shareServiceOauthInfoForNotification:(NSNotification *)note
{
    return [[[note userInfo] objectForKey:SNShareServiceOauthInfoKey] autorelease];
}

+ (void)postNotificationName:(NSString *)name
                      object:(id)object
                 serviceType:(SNShareClientType)type
                    userInfo:(NSDictionary *)userInfo
{
    NSMutableDictionary *serviceInfo = [[NSMutableDictionary alloc] initWithCapacity:3];
    [serviceInfo setObject:name forKey:SNShareServiceNotificationNameKey];
    [serviceInfo setObject:[NSNumber numberWithInt:type] forKey:SNShareServiceTypeKey];
    [serviceInfo setValue:userInfo forKey:SNShareServiceUserInfoKey];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:name
                                                        object:object
                                                      userInfo:serviceInfo];
    
    [serviceInfo release];
}

+ (void)postNotificationName:(NSString *)name
                 serviceType:(SNShareClientType)type
                    userInfo:(NSDictionary *)userInfo
{
    [[self class] postNotificationName:name
                                object:nil
                           serviceType:type
                              userInfo:userInfo];
}

+ (void)postNotificationName:(NSString *)name
                 serviceType:(SNShareClientType)type
{
    [[self class] postNotificationName:name
                                object:nil
                           serviceType:type
                              userInfo:nil];
}

+ (void)postNotificationName:(NSString *)name
                      object:(id)object
                 serviceType:(SNShareClientType)type
        shareServiceUserInfo:(ShareClientUserInfo *)userInfo
{
    NSMutableDictionary *serviceInfo = [[NSMutableDictionary alloc] initWithCapacity:3];
    [serviceInfo setObject:name forKey:SNShareServiceNotificationNameKey];
    [serviceInfo setObject:[NSNumber numberWithInt:type] forKey:SNShareServiceTypeKey];
    [serviceInfo setValue:userInfo forKey:SNShareServiceUserInfoKey];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:name
                                                        object:object
                                                      userInfo:serviceInfo];
    
    [serviceInfo release];
}

+ (void)postNotificationName:(NSString *)name
                      object:(id)object
                 serviceType:(SNShareClientType)type
        shareServiceOauthInfo:(ShareClientOAuthInfo *)userInfo
{
    NSMutableDictionary *serviceInfo = [[NSMutableDictionary alloc] initWithCapacity:3];
    [serviceInfo setObject:name forKey:SNShareServiceNotificationNameKey];
    [serviceInfo setObject:[NSNumber numberWithInt:type] forKey:SNShareServiceTypeKey];
    [serviceInfo setValue:userInfo forKey:SNShareServiceOauthInfoKey];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:name
                                                        object:object
                                                      userInfo:serviceInfo];
    
    [serviceInfo release];
}



+ (void)postNotificationName:(NSString *)name
                 serviceType:(SNShareClientType)type
        shareServiceUserInfo:(ShareClientUserInfo *)userInfo
{
    [[self class] postNotificationName:name
                                object:nil
                           serviceType:type
                  shareServiceUserInfo:userInfo];
}

+ (void)postNotificationName:(NSString *)name
                 serviceType:(SNShareClientType)type
        shareServiceOauthInfo:(ShareClientOAuthInfo *)userInfo
{
    [[self class] postNotificationName:name
                                object:nil
                           serviceType:type
                  shareServiceOauthInfo:userInfo];
}

@end
